// 题目一：将下面异步代码使用promise的方式改写
setTimeout(function () {
    var a = 'hello ';
    setTimeout(function () {
        var b = 'lagou ';
        setTimeout(function () {
            var c = 'I Love U';
            console.log(a + b + c);
        }, 10)
    }, 10)
}, 10)


// promise 改写
new Promise((resolve, reject) => {
    setTimeout(function () {
        var a = 'hello ';
        resolve(a);
    }, 10)
}).then(function (a) {
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            var b = 'lagou ';
            resolve([a, b]);
        }, 10)
    })
}).then(function ([a, b]) {
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            var c = 'I Love U';
            resolve([a, b, c]);
        }, 10)
    })
}).then(function ([a, b, c]) {
    console.log(a + b + c);
})


// async 改写
let hello = new Promise((resolve, reject) => {
    setTimeout(function () {
        var a = 'hello ';
        resolve(a)
    }, 10)
});
let lagou = new Promise((resolve, reject) => {
    setTimeout(function () {
        var b = 'lagou ';
        resolve(b)
    }, 10)
});
let loveu = new Promise((resolve, reject) => {
    setTimeout(function () {
        var c = 'I Love U';
        resolve(c)
    }, 10)
});
async function run() {
    let a = await hello;
    let b = await lagou;
    let c = await loveu;
    console.log(a + b + c);
}
run();

